import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import tailwindcss from '@tailwindcss/vite'

// https://vite.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		vueDevTools(),
		tailwindcss(),
	],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url)),
			'views': fileURLToPath(new URL('./src/Views', import.meta.url)),
		},
	},
	css: {
		preprocessorOptions: {
			// 全局变量引入
			scss: {
				additionalData: '@import "/src/assets/css/default.scss";'
			}
		}
	},
	build: {
		chunkSizeWarningLimit: 1000,
		rollupOptions: {
			output: {
				manualChunks: id => {
					if (id.indexOf('echarts') > -1) {
						return 'echarts';
					}
					if (id.indexOf('wangeditor') > -1) {
						return 'wangeditor';
					}
				},
			}
		}
	},
	define: {
		// 'process.env': loadEnv(mode, process.cwd())
	},
	server: {
		host: "localhost",
		port: 5175,
		proxy: {
			'/dev': {
				target: 'http://8.129.10.102:8080',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/dev/, '')
			}
		}
	}
})
